package com.itawei.TCPpractise.num4;

import java.io.*;
import java.net.Socket;

/**
 * 客户端：将本地文件上传到服务器。接收服务器的反馈
 * 服务器：接收客户端上传的文件，上传完毕之后给出反馈
 */
public class Client {
    public static void main(String[] args) throws IOException {
        //1.创建socket对象
        Socket socket = new Socket("127.0.0.1", 10086);
        //2.创建缓冲流 然后把本地文件输出到服务器
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Program Files\\Java\\code\\javaseadvrepro\\aaa\\a.jpg"));
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }
        //往服务器写出结束标记
        socket.shutdownOutput();

        //3.接收服务器反馈
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(br.readLine());

        //4.释放资源
        socket.close();

    }
}
